# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
load("//pw_bloat:pw_size_diff.bzl", "pw_size_diff")
load("//pw_bloat:pw_size_table.bzl", "pw_size_table")
load("//pw_bluetooth_proxy:bt-proxy.bzl", "pw_bluetooth_proxy_library", "pw_bluetooth_proxy_test")
load("//pw_build:compatibility.bzl", "incompatible_with_mcu")

package(
    default_visibility = ["//visibility:public"],
    features = [
        "-layering_check",
        "-ctad_warnings",
    ],
)

licenses(["notice"])

pw_bluetooth_proxy_library(
    name = "pw_bluetooth_proxy",
)

pw_bluetooth_proxy_library(
    name = "pw_bluetooth_proxy_v1",
    testonly = True,
    defines = ["PW_BLUETOOTH_PROXY_MULTIBUF=PW_BLUETOOTH_PROXY_MULTIBUF_V1"],
    visibility = ["//visibility:private"],
)

pw_bluetooth_proxy_library(
    name = "pw_bluetooth_proxy_v2",
    testonly = True,
    defines = ["PW_BLUETOOTH_PROXY_MULTIBUF=PW_BLUETOOTH_PROXY_MULTIBUF_V2"],
    visibility = ["//visibility:private"],
)

# Module configuration

cc_library(
    name = "config",
    hdrs = ["public/pw_bluetooth_proxy/config.h"],
    strip_include_prefix = "public",
    deps = [":config_override"],
)

label_flag(
    name = "config_override",
    build_setting_default = "//pw_build:default_module_config",
)

# Tests

pw_bluetooth_proxy_test(
    name = "pw_bluetooth_proxy_v1_test",
    versioned_deps = [
        ":pw_bluetooth_proxy_v1",
        "//pw_multibuf:simple_allocator",
    ],
)

pw_bluetooth_proxy_test(
    name = "pw_bluetooth_proxy_v2_test",
    versioned_deps = [":pw_bluetooth_proxy_v2"],
)

filegroup(
    name = "doxygen",
    srcs = [
        "public/pw_bluetooth_proxy/config.h",
        "public/pw_bluetooth_proxy/h4_packet.h",
        "public/pw_bluetooth_proxy/proxy_host.h",
    ],
)

pw_size_diff(
    name = "use_passthrough_proxy_size_diff",
    base = "//pw_bloat:bloat_base",
    label = "Create and use proxy as a simple passthrough",
    target = "//pw_bluetooth_proxy/size_report:use_passthrough_proxy",
)

pw_size_table(
    name = "use_passthrough_proxy_size_report",
    reports = [
        ":use_passthrough_proxy_size_diff",
    ],
)

sphinx_docs_library(
    name = "docs",
    srcs = [
        "docs.rst",
        "proxy_host_test.cc",
        ":use_passthrough_proxy_size_report",
    ],
    prefix = "pw_bluetooth_proxy/",
    target_compatible_with = incompatible_with_mcu(),
)
